<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>生产工时日报</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div class="mini-splitter" style="width: 100%; height: 100%;">
		<div size="240" showCollapseButton="true">
			<div class="mini-fit">
				<ul id="pageTree" class="mini-tree" style="width: 100%;" showTreeIcon="true" allowDrag="true" allowDrop="true" textField="departName"
					idField="departID" resultAsTree="false">
				</ul>
			</div>
		</div>

		<div showCollapseButton="true">
			<fieldset id="fd1" style="width: 97%; margin-bottom: 4px;">
				<legend><span>查询条件</span></legend>
				<div id="queryForm" class="fieldset-body">
					<table class="form-table" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="form-label">
								<span>姓名：</span>
								<div id="txtUserID" class="mini-autocomplete" style="width:150px;" popupWidth="200" textField="userName" valueField="userID">
									<div property="columns">
										<div header="姓名" field="userName" width="40"></div>
										<div header="编号" field="workNo"></div>
									</div>
								</div>
								<span>日期从：</span>
								<input id="calendarDate_from" name="calendarDate_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<span>到：</span>
								<input id="calendarDate_to" name="calendarDate_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="doSearch()">查询</a>
								<!-- <a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="doCompute()">计算</a> -->
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="batchCompute()">重新计算</a>
								<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-save" onclick="doSave()">保存</a>
								<a class="mini-menubutton " menu="#popupMenu2">导出</a>
								<ul id="popupMenu2" class="mini-menu" style="display:none;">
									<li iconCls="icon-save" onclick="downloadDayReport()">导出日报</li>
									<li iconCls="icon-save" onclick="downloadMonthReport()">导出月报</li>
								</ul>
							</td>
						</tr>
					</table>
				</div>
			</fieldset>

			<div class="mini-fit">
				<div id="datagrid" class="mini-datagrid" style="width:130%;height:100%;" pageSize="20" multiSelect="true">
				</div>
			</div>
		</div>
	</div>

</body>

<script type="text/javascript">
	var userID = null;
	var localUser = mini.decode(localStorage.getItem('user'));
	if (localUser == null) {
		alert("你还没有登录，请先登录再操作...");
	} else {
		userID = localUser.userID;
	}

	miniInit();

	var tree = mini.get("pageTree");
	http.get('/sys/depart/list.do', function (page) {
		tree.loadData(page);
	});
	var editNode = null; // 当前编辑的节点
	/*********************************************************
	 * 左侧目录树的鼠标点击事件
	 *********************************************************/
	tree.on("nodedblclick", function (e) {
		// debugger
		editNode = e.node;
		http.get('/sys/depart/list.do?departID=' + editNode.departID, function (page) {
			tree.addNodes(page, editNode);
			tree.expandNode(editNode);
		});
	});

	var txtUserID = mini.get("txtUserID");
	txtUserID.setName("userID");
	txtUserID.set({
		url: http.getUrl("/user/page.do")
	});

	// 设置截止日期至今天
	var date = new Date();
	mini.get("calendarDate_to").setValue(date);
	date.setDate(date.getDate() - 5);
	mini.get("calendarDate_from").setValue(date);

	var queryForm = new mini.Form("#queryForm");
	var datagrid = mini.get("datagrid");
	datagrid.set({
		columns: [
			{ type: "indexcolumn", width: 15 },
			{ type: "checkcolumn", width: 15 },
			{ width: 0, headerAlign: "center", field: "projectDayID", header: "主键" },
			{ width: 0, headerAlign: "center", field: "projectID", header: "主键" },
			{ width: 0, headerAlign: "center", field: "userID", header: "主键" },
			/* { width: 60, headerAlign: "center", field: "departName", header: "部门名称" }, */
			{ width: 50, headerAlign: "center", field: "workNo", header: "员工工号" },
			{ width: 50, headerAlign: "center", field: "userName", header: "员工姓名" },
			{ width: 80, headerAlign: "center", field: "startWorkTime", header: "上班时间" },
			{ width: 80, headerAlign: "center", field: "endWorkTime", header: "下班时间" },
			{ width: 100, headerAlign: "center", field: "cardRecord", header: "考勤记录" },
			{ width: 50, headerAlign: "center", field: "workTime", header: "工作时长", editor: { type: "textbox" } },
			{ width: 50, headerAlign: "center", field: "overTimeDay", header: "平日加班", editor: { type: "textbox" } },
			{ width: 50, headerAlign: "center", field: "overTimeWeekend", header: "假日加班", editor: { type: "textbox" } },
			{ width: 50, headerAlign: "center", field: "overTimeHoliday", header: "节日加班", editor: { type: "textbox" } },
			{ width: 50, headerAlign: "center", field: "totalWorkTime", header: "工作总时长", editor: { type: "textbox" } },
			{ width: 50, headerAlign: "center", field: "checkStlye", header: "考勤方式" },
			{ width: 50, headerAlign: "center", field: "checkUserName", header: "考勤管理员" },
			{ width: 50, headerAlign: "center", field: "remark", header: "说明" }
		]
	});

	function doSearch() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		data["departID"] = 'ROOT';
		data["departID_link"] = "like";
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
		}
		http.post("/day/report/day/list.do", data, function (page) {
			if (page.success) {
				debugger
				datagrid.setData(page.data);
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}

	function doSave() {
		if (userID == null) {
			alert("你还没有登录，请先登录再操作...");
			return;
		}
		miniui.mask("数据保存中...");
		var list = datagrid.getChanges("modified", false);
		var data = {
			checkUserID: userID,
			json: mini.encode(list)
		};
		debugger
		http.post("/day/report/savetDayReportList.do", data, function (page) {
			if (page.success) {
				mini.alert("保存成功！", "提示", null);
				datagrid.accept();
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}

	function doCompute() {
		miniui.mask("数据保存中...");
		var list = datagrid.getSelecteds();
		if (list.length == 0) {
			miniui.showErrorMessageBox("请先选择要计算的数据...");
			return;
		}
		var ids = common.getListKeys(list, "dayReportID");
		var data = {
			"ids": ids
		}
		http.post("/day/report/computetDayReportList.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				miniui.showSuccessTip("保存成功");
				datagrid.reload();
			} else {
				miniui.showErrorMessageBox(page.message);
			}
		});
	}

	function downloadDayReport() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
		}/*  else {
			data["departID"] = 'ROOT';
			data["departName"] = "全部";
		} */
		http.post("/day/report/any/listDayReportOutput.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				mini.alert("数据处理成功，准备下载!", "提示", null);
				var url = http.getUrl("/file/any/getFile.do");
				jQuery('<form action="' + url + '"method=post">' + // action请求路径及推送方法
					'<input type="text" name="url" value="' + page.dataMap.filename + '"/>' + // 文件路径
					'</form>')
					.appendTo('body').submit().remove();
			} else {
				mini.alert(page.message, "提示", null);
			}
		});
	}

	function downloadMonthReport() {
		miniui.mask("数据加载中...");
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
		}/*  else {
			data["departID"] = 'ROOT';
			data["departName"] = "全部";
		} */
		http.post("/day/report/any/listMonthReportOutput.do", data, function (page) {
			mini.unmask();
			if (page.success) {
				mini.alert("数据处理成功，准备下载!", "提示", null);
				var url = http.getUrl("/file/any/getFile.do");
				jQuery('<form action="' + url + '"method=post">' + // action请求路径及推送方法
					'<input type="text" name="url" value="' + page.dataMap.filename + '"/>' + // 文件路径
					'</form>')
					.appendTo('body').submit().remove();
			} else {
				mini.alert(page.message, "提示", null);
			}
		});
	}

	function batchCompute() {
		miniui.mask("数据处理中...");
		var data = queryForm.getData(true, false);
		var node = tree.getSelectedNode();
		if (node) {
			data["departID"] = node.departID;
			data["departID_link"] = "like";
		}
		http.post("/day/report/batchCompute.do", data, function (page) {
			if (page.success) {
				miniui.showInfoMessageBox(page.message);
			} else {
				miniui.showLoadErrorMessageBox(page.message);
			}
			mini.unmask();
		});
	}

</script>

</html>